
<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.sinba.common.system.service.IBuyCreditsService"%>
<%@page import="com.sinba.common.system.dto.BuyCreditsQueryDTO"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ include file="../language.jsp" %>
<%
	if(session.getAttribute("password2")==null){
	response.sendRedirect( "login2.jsp?pageUrl=user/buyMain.jsp");
	return;
	}
	ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	
	BuyCreditsQueryDTO qdto = new BuyCreditsQueryDTO(); 
	qdto.setLinkCode((String)session.getAttribute("linkCodeStart"));
	qdto.setStatus(0);
	IBuyCreditsService buyCreditsService = (IBuyCreditsService)ac.getBean("buyCreditsService");
	int pages = 1;
	if(request.getParameter("pages")!=null && request.getParameter("_pages")!=""){
		pages = Integer.parseInt(request.getParameter("pages"));
	}
	
	if(request.getParameter("guaDanUser")!=null && request.getParameter("_guaDanUser")!=""){
		qdto.setLoginName(request.getParameter("guaDanUser"));
	}
	
	if(request.getParameter("buyRange")!=null && request.getParameter("_buyRange")!=""){
		if("L1".equals(request.getParameter("buyRange"))){
			qdto.setStartRange(0D);
			qdto.setEndRange(50D);
		}
		if("L2".equals(request.getParameter("buyRange"))){
			qdto.setStartRange(51D);
			qdto.setEndRange(100D);
		}
		if("L3".equals(request.getParameter("buyRange"))){
			qdto.setStartRange(101D);
			qdto.setEndRange(150D);
		}
		if("L4".equals(request.getParameter("buyRange"))){
			qdto.setStartRange(151D);
			qdto.setEndRange(200D);
		}
		if("L5".equals(request.getParameter("buyRange"))){
			qdto.setStartRange(201D);
			qdto.setEndRange(500D);
		}
		if("L6".equals(request.getParameter("buyRange"))){
			qdto.setStartRange(501D);
			qdto.setEndRange(1000D);
		}
		if("L7".equals(request.getParameter("buyRange"))){
			qdto.setStartRange(1001D);
			qdto.setEndRange(1500D);
		}
		if("L8".equals(request.getParameter("buyRange"))){
			qdto.setStartRange(1501D);
			qdto.setEndRange(2000D);
		}
		
	}
	
	int rows = 20;
	int start = ( pages - 1 ) * rows;
	qdto.setStart(start);
	qdto.setLimit(rows);
	PageDTO pageDTO = buyCreditsService.findBuyCreditsPager(qdto, "asc", "createTime");
	pageDTO.setPage( pages );
	pageDTO.setRows( rows );
	request.setAttribute("pageDTO",pageDTO);
	
	request.setAttribute("loginName",(String)session.getAttribute("loginName"));
	
	request.setAttribute("buyRange",request.getParameter("buyRange"));
	
%>
<fmt:setLocale value="${empty cookie['language'].value?'zh_CN':cookie['language'].value}"/>
	<fmt:setBundle basename="i18n.itilbase"/>
	<c:set var="lang" value="${empty cookie['language'].value?'zh_CN':cookie['language'].value}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta charset="UTF-8">
<title>卖出列表</title>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1" />


<!-- Bootstrap framework -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet" href="bootstrap/css/bootstrap-responsive.min.css" />
<!-- breadcrumbs-->
	<link rel="stylesheet" href="lib/jBreadcrumbs/css/BreadCrumb.css" />
<!-- main styles -->
    <link rel="stylesheet" href="css/sub_page_main_style.css" />

<!--[if lte IE 8]>
    <link rel="stylesheet" href="css/ie.css" />
    <script src="js/ie/html5.js"></script>
    <script src="js/ie/respond.min.js"></script>
<![endif]-->

</head>
<body style="height:800px">

<!-- 主体内容 -->
<div id="contentwrapper">
	<div class="main_content">
		 <nav>
            <div id="jCrumbs" class="breadCrumb module">
                <ul>
                    <li>
                        <a href="main.jsp"><i class="icon-home"></i></a>
                    </li>
                    <li>
                        <a href="#"><fmt:message key="i18n.moneyManage"/></a>
                    </li>
                    <li>
                        <a href="#">卖出列表</a>
                    </li>
                </ul>
            </div>
         </nav>	
         
	<div class="listCont">
    	<div class="listTable lttno">
			<div>
					<select id="buyRange" onchange="changeBuyRange(this.value)">
						<option value="">请选择卖出金额区间</option>
						<option value="L1" <c:if test="${buyRange eq 'L1'}">selected="selected"</c:if>>1~50</option>
						<option value="L2" <c:if test="${buyRange eq 'L2'}">selected="selected"</c:if>>51~100</option>
						<option value="L3" <c:if test="${buyRange eq 'L3'}">selected="selected"</c:if>>101~150</option>
						<option value="L4" <c:if test="${buyRange eq 'L4'}">selected="selected"</c:if>>151~200</option>
						<option value="L5" <c:if test="${buyRange eq 'L5'}">selected="selected"</c:if>>201~500</option>
						<option value="L6" <c:if test="${buyRange eq 'L6'}">selected="selected"</c:if>>501~1000</option>
						<option value="L7" <c:if test="${buyRange eq 'L7'}">selected="selected"</c:if>>1001~1500</option>
						<option value="L8" <c:if test="${buyRange eq 'L8'}">selected="selected"</c:if>>1501~2000</option>
					</select>
					
					搜索挂单会员编号:<input style="width: 80px;" id="guaDanUser" />
					<input type="button" value="搜索" onclick="searchBuy()">
			</div>
			<script type="text/javascript">
				function changeBuyRange(buyRange){
					window.location.href="buyMain.jsp?buyRange="+buyRange;
				}
				function searchBuy(){
					window.location.href="buyMain.jsp?guaDanUser="+$('#guaDanUser').val();
				}
			</script>
    		<!-- 提现记录 -->
		        <div style="padding: 5px;" align="left" >
		        	<form id="cashBusiness_form">
		        	<table width="100%" id="tr_cashBusiness_table" class="table table-bordered table-striped">
	        			<tr>
	        				<th>序号</th>
	        				<th>卖出会员</th>
	        				<th>金额</th>
	        				<th>卖出时间</th>
	        				<th>账号类型</th>
	        				<th>账号</th>
	        				<th>微信</th>
	        				<th>手机</th>
	        				<th>状态</th>
	        				<th>操作</th>
	        			</tr>
		        		<c:if test="${pageDTO.totalSize eq 0}">
						<tr><td colspan="10" align="center"><fmt:message key="i18n.noData"/>!</td></tr>
						</c:if>	
						<c:if test="${pageDTO.totalSize ne 0}">
							<c:forEach items="${pageDTO.data}" var="data" varStatus="status">
							<tr>
								<td>${status.index+1}</td>
								<td>
								${fn:substring(data.loginName, 2, 10)}**
								(**${fn:substring(data.loginUserName, 1, 5)})</td>
								<td>${data.buyMoney*0.95 }</td>
								
								<td><fmt:formatDate value="${data.buyTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
								<td>${data.accountType}</td>
								<td>${data.bankAccount}</td>
								<td>${data.weiXin}</td>
								<td>${data.mobileNo}</td>
								<td>
									<c:if test="${data.status eq 0}"><span style="color:red;">待卖出</span></c:if>
									<c:if test="${data.status eq 1}">运营中心已买入,请确认!</c:if>
									<c:if test="${data.status eq 2}"><span style="color:green;">卖出成功</span></c:if>
								</td>
								<td>
									<c:if test="${data.status eq 0}">
										<a id="buyCredits_${data.id}" href="javascript:buyCredits('${data.id}','${loginName}')">买入</a>
									</c:if>
								</td>
							</tr>
							</c:forEach>
						</c:if>       		
		        	</table>
		        	</form>
		        	
		        	
		        	
				<!-- end 提现记录 -->
    		
    			<form action="buyCredits!creditsOpt.action" id="buyCredits_form" method="post">
				</form>
    	</div>
    </div>	
</div>
				
</div>
</div>

<script type="text/javascript" src="../scripts/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../scripts/user/common.js"></script>
<script>

var isclick=true;
function buyCredits(id,loginName){
	
	$('#buyCredits_form').html("<input type='hidden' name='pageUrl' value='myBuy.jsp' />"+
			"<input type='hidden' name='buyCreditsDTO.optType' value='buyCredits' />"+
			"<input type='hidden' name='buyCreditsDTO.operationsCenter' value='"+loginName+"' />"+
			"<input type='hidden' name='buyCreditsDTO.id' value='"+id+"' />");
	if(confirm('Are you sure you want to buy(是否确定要买入)?')){
		$('#buyCreditsr_'+id).attr("disabled",true);
		if(isclick){
			isclick=false;
			$('#buyCredits_form').submit();
		}else{
			alert('操作过于频繁，请稍后再操作!');
		}
		
	}
}
</script>


</body>
</html>